home *** CD-ROM | disk | FTP | other *** search
File List | 1983-11-17 | 15.2 KB | 302 lines |
- The Microsoft MACRO Assembler 11-17-83 PAGE 1-1
- 'FREE --- report free space on disk'
-
-
- 1 name free
- 2 page 60,132
- 3 title 'FREE --- report free space on disk'
- 4
- 5 ;FREE --- a utility to report free space on
- 6 ; the default or selected disk drive.
- 7 ;
- 8 ;Requires PC-DOS or MS-DOS 2.0
- 9 ;
- 10 ;Used in the form:
- 11 ;A>FREE [unit:]
- 12 ;(item in square brackets is optional)
- 13 ;
- 14 ;version 1.0 July 1, 1984
- 15 ;Copyright (c) 1984 by Ray Duncan
- 16 ;May be freely reproduced for non-commercial use.
- 17
- 18 = 000D cr equ 0dh ;ASCII carriage return
- 19 = 000A lf equ 0ah ;ASCII line feed
- 20 = 0020 blank equ 20h ;ASCII space code
- 21 = 0024 eom equ '$' ;end of string marker
- 22
- 23
- 24 ;Here we define a dummy segment containing lavbels
- 25 ;for thedefault fiel control black and the command tail buffer,
- 26 ;so that the main program can access those locations.
- 27 ;
- 28 0000 psp segment para public 'PSP'
- 29
- 30 005C org 05ch
- 31 005C fcb label byte ;default file control block
- 32
- 33 0080 org 080h
- 34 0080 command label byte ;default command buffer
- 35
- 36 0080 psp ends
- 37
- 38 0000 cseg segment para public'CODE'
- 39
- 40 assume cs:cseg,ds:psp,es:data,ss:stack
- 41
- 42 0000 get_drive proc near ;get drive selection, if any,
- 43 ;otherwise obtain the identity
- 44 ;of the current disk drive.
- 45 ;Return drive (1=A,2=B,etc)in RL.
- 46 ;
- 47 0000 A0 005C R mov al,fcb ;Pick up the drive code, parsed
- 48 ;by DOS into the default file
- 49 ;control block.
- 50 0003 0A C0 or al,al ;Is it the default?
- 51 0005 75 06 jnz get_drive1 ;no, use it
- 52 0007 B4 19 mov ah,19h ;Yes, get the actual current
- 53 0009 CD 21 int 21h ;drive from PC-DOS.
- 54 000B FE C0 inc al ;Increment to match FCB code.
- 55 000D get_drive1: ;Return drive code in RL.
- The Microsoft MACRO Assembler 11-17-83 PAGE 1-2
- 'FREE --- report free space on disk'
-
-
- 56 000D C3 ret
- 57 000E get_drive endp
- 58
- 59 000E free proc far ;entry point from PC-DOS
- 60 000E 1E push ds ;Save OS:0000 for final
- 61 000F 33 C0 xor ax,ax ;return to PC-DOS
- 62 0011 50 push ax
- 63 0012 B8 ---- R mov ax,data ;make our data segment
- 64 0015 8E C0 mov es,ax ;addressable via ES register.
- 65 0017 B4 30 mov ah,30h ;check version of PC-DOS.
- 66 0019 CD 21 int 21h
- 67 001B 3C 02 cmp al,2
- 68 001D 73 0A jae free1 ;proceed, DOS 2.0 or greater.
- 69 001F BA 0048 R mov dx,offset msg2 ;DOS 1.x -- print error message
- 70 0022 8C C0 mov ax,es ;and exit. First fix up DS register
- 71 0024 8E D8 mov ds,ax ;;so error message is addressable.
- 72 0026 EB 01 90 jmp free1
- 73
- 74 0029 E8 0000 R free1: call get_drive ;get drive selection into DL.
- 75 002C 06 push es ;copy ES to Ds for remainder
- 76 002D 1F pop ds ;of the program...
- 77 assume ds:data ;and tell assembler about it.
- 78 002E 8A D0 mov dl,al
- 79 0030 04 40 add al,'A'-1 ;form drive letter from drive soce,
- 80 0032 A2 001F R mov outputb,al ;and put i into the ouput string.
- 81 0035 B4 36 mov ah,36h ;nob call dos to get free disk space
- 82 0037 CD 21 int 21h
- 83 0039 3D FFFF cmp ax,-1 ;was drive invalid?
- 84 003C 74 13 je free3 ;yes, go print error message
- 85 ;drive was ok, so now registers are.
- 86
- 87 ;RX=number of sectors per cluser
- 88 ;BX=available clusters,
- 89 ;CX=number of bytes per sector,
- 90 ;DX=total clusters per drive.
- 91 ;calculate free space:
- 92 003E F7 E1 mul cx ;sectors per cluster * bytes/sector
- 93 ;(we assume no overflow into DX
- 94 0040 F7 E3 mul bx ;then* available clusers
- 95 0042 BE 000B R mov si,offset (outputa+9)
- 96 0045 B9 000A mov cx,10 ;CX = 10, radix for conversion
- 97 0048 E8 0059 R call bin_to_asc ;convert free space value to ASCII,
- 98 004B BA 0000 R mov dx,offset output
- 99 004E EB 04 90 jmp free4 ;and print it out.
- 100
- 101 0051 BA 0024 R free3: mov dx,offset msg1 ;illegal drive, print error
- 102
- 103 0054 B4 09 free4: mov ah,9 ;prin the string whose address
- 104 0056 CD 21 int 21h ;is in DX.
- 105 0058 CB ret ;then return to DOS.
- 106
- 107 0059 free endp
- 108
- 109 ;Convert 32 bit binary value to ASCII string.
- 110 ;
- The Microsoft MACRO Assembler 11-17-83 PAGE 1-3
- 'FREE --- report free space on disk'
-
-
- 111 ;Call with DX:AX = signed 32 but value
- 112 ; CX = radix
- 113 ; SI = last byte of area to store resulting string
- 114 ; (make sure enough room is available to store
- 115 ; the string in the radix you have selected.)
- 116 ;
- 117 ;Destroys RX,BX,CX,DX, and SI.
- 118 ;
- 119 0059 bin_to_asc proc near ;convert DX:AX to ASCII.
- 120 ;force storage of at least 1 digit.
- 121 0059 C6 04 30 mov byte ptr [si],'0'
- 122 005C 0B D2 or dx,dx ;test sign of 32 bit value,
- 123 005E 9C pushf ;and save sign on stack.
- 124 005F 79 0A jns bin1 ;jump if it was positive.
- 125 0061 F7 D2 not dx ;it was negative, take 2's complemen
- 126
- 127 0063 F7 D0 not ax ;of the value.
- 128 0065 05 0001 add ax,1
- 129 0068 83 D2 00 adc dx,0
- 130 006B bin1: ;divide the 32 bit balue by the radi
- 131
- 132 ;to extract the next digit for the
- 133 ;forming string.
- 134 006B 8B D8 mov bx,ax ;is the value zero yet?
- 135 006D 0B DA or bx,dx
- 136 006F 74 13 jz bin3 ;yes, we are done converting.
- 137 0071 E8 008B R call divide ;no, divide by radix.
- 138 0074 80 C3 30 add bl,'0' ;convert the remainder to an ASCII
- 139 0077 80 FB 39 cmp bl,'9' ;we might be converting to hex ASCII
- 140
- 141 007A 7E 03 jle bin2 ;jump if in range 0-9,
- 142 007C 80 C3 07 add bl,'A'-'9'-1 ;correct it if in range A-F.
- 143 007F 88 1C bin2: mov [si],bl ;store this character into string.
- 144 ;to extract the next digit for the
- 145 ;forming string.
- 146 0081 4E dec si ;back up throught string,
- 147 0082 EB E7 jmp bin1 ;and so it again.
- 148 0084 bin3: ;restore sign flag,
- 149 0084 9D popf ;was original value negative?
- 150 0085 79 03 jns bin4 ;no, jump
- 151 ;yes, store sign into ouput string.
- 152 0087 C6 04 2D mov byte ptr[si],'-'
- 153 008A C3 bin4: ret ;back to caller.
- 154 008B bin_to_asc endp
- 155
- 156
- 157 ;General purpose 32 bit by 16 bit unsigned divide.
- 158 ;This must be used instead of the plain machine unsigned divide
- 159 ;for cases where the quotient may overflow 16 bits (for example,
- 160 ;dividing 100,000 by 2). If called with a zero divisor, this
- 161 ;routine returns the dividend unchanged and gives no warning.
- 162 ;
- 163 ;Call with DX:AX = 32 bit dividend
- 164 ; CX = divisor
- 165 ;
- The Microsoft MACRO Assembler 11-17-83 PAGE 1-4
- 'FREE --- report free space on disk'
-
-
- 166 ;Returns DX:AX = quotient
- 167 ; BX = remainder
- 168 ; CX = divisor (unchanged)
- 169 ;
- 170
- 171 008B divide proc near ;Divide DX:AX by CX
- 172 008B E3 0E jcxz div1 ;exit if divide by zero
- 173 008D 50 push ax ;0:dividend_upper/divisor
- 174 008E 8B C2 mov ax,dx
- 175 0090 33 D2 xor dx,dx
- 176 0092 F7 F1 div cx
- 177 0094 8B D8 mov bx,ax ;BX = quotient1
- 178 0096 58 pop ax ;remainder1:dividend_lower.divisor
- 179 0097 F7 F1 div cx
- 180 0099 87 DA xchg bx,dx ;DX:RX = quotient1:quotient2
- 181 009B C3 div1: ret ;BX = remainder2
- 182 009C divide endp
- 183 009C cseg ends
- 184
- 185
- 186 0000 data segment para public 'DATA'
- 187
- 188 0000 0D 0A output db cr,lf
- 189 0002 0A [ outputa db 10 dup(blank)
- 190 20
- 191 ]
- 192
- 193
- 194
- 195 000C 62 79 74 65 73 20 db 'bytes free on drive'
- 196 66 72 65 65 20 6F
- 197 6E 20 64 72 69 76
- 198 65
- 199
- 200
- 201 001F 78 3A 0D 0A 24 outputb db 'x:',cr,lf,eom
- 202
- 203 0024 0D 0A msg1 db cr,lf
- 204 0026 54 68 61 74 20 64 db 'That disk drive does not exist.'
- 205 69 73 6B 20 64 72
- 206 69 76 65 20 64 6F
- 207 65 73 20 6E 6F 74
- 208 20 65 78 69 73 74
- 209 2E
- 210
- 211
- 212 0045 0D 0A 24 db cr,lf,eom
- 213
- 214 0048 0D 0A msg2 db cr,lf
- 215 004A 52 65 71 75 69 72 db 'Requires DOS version 2 or greater.'
- 216 65 73 20 44 4F 53
- 217 20 76 65 72 73 69
- 218 6F 6E 20 32 20 6F
- 219 72 20 67 72 65 61
- 220 74 65 72 2E
- The Microsoft MACRO Assembler 11-17-83 PAGE 1-5
- 'FREE --- report free space on disk'
-
-
- 221
- 222
- 223
- 224 006C 0D 0A 24 db cr,lf,eom
- 225 006F data ends
- 226
- 227 0000 stack segment para stack 'STACK'
- 228 0000 40 [ db 64 dup (?)
- 229 ??
- 230 ]
- 231
- 232
- 233 0040 stack ends
- 234
- 235 end free
-
- The Microsoft MACRO Assembler 11-17-83 PAGE Symbols-1
- 'FREE --- report free space on disk'
-
-
- Segments and groups:
-
- N a m e Size align combine class
-
- CSEG . . . . . . . . . . . . . . 009C PARA PUBLIC 'CODE'
- DATA . . . . . . . . . . . . . . 006F PARA PUBLIC 'DATA'
- PSP. . . . . . . . . . . . . . . 0080 PARA PUBLIC 'PSP'
- STACK. . . . . . . . . . . . . . 0040 PARA STACK 'STACK'
-
- Symbols:
-
- N a m e Type Value Attr
-
- BIN1 . . . . . . . . . . . . . . L NEAR 006B CSEG
- BIN2 . . . . . . . . . . . . . . L NEAR 007F CSEG
- BIN3 . . . . . . . . . . . . . . L NEAR 0084 CSEG
- BIN4 . . . . . . . . . . . . . . L NEAR 008A CSEG
- BIN_TO_ASC . . . . . . . . . . . N PROC 0059 CSEG Length =0032
- BLANK. . . . . . . . . . . . . . Number 0020
- COMMAND. . . . . . . . . . . . . L BYTE 0080 PSP
- CR . . . . . . . . . . . . . . . Number 000D
- DIV1 . . . . . . . . . . . . . . L NEAR 009B CSEG
- DIVIDE . . . . . . . . . . . . . N PROC 008B CSEG Length =0011
- EOM. . . . . . . . . . . . . . . Number 0024
- FCB. . . . . . . . . . . . . . . L BYTE 005C PSP
- FREE . . . . . . . . . . . . . . F PROC 000E CSEG Length =004B
- FREE1. . . . . . . . . . . . . . L NEAR 0029 CSEG
- FREE3. . . . . . . . . . . . . . L NEAR 0051 CSEG
- FREE4. . . . . . . . . . . . . . L NEAR 0054 CSEG
- GET_DRIVE. . . . . . . . . . . . N PROC 0000 CSEG Length =000E
- GET_DRIVE1 . . . . . . . . . . . L NEAR 000D CSEG
- LF . . . . . . . . . . . . . . . Number 000A
- MSG1 . . . . . . . . . . . . . . L BYTE 0024 DATA
- MSG2 . . . . . . . . . . . . . . L BYTE 0048 DATA
- OUTPUT . . . . . . . . . . . . . L BYTE 0000 DATA
- OUTPUTA. . . . . . . . . . . . . L BYTE 0002 DATA Length =000A
- OUTPUTB. . . . . . . . . . . . . L BYTE 001F DATA
-
- Warning Severe
- Errors Errors
- 0 0